package com.ourteam.system.api;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ourteam.frame.controller.AbstractTreeBuilderController;
import com.ourteam.frame.web.TreeParamModel;
import com.ourteam.frame.web.TreeViewNodeBean;

@Controller
@CrossOrigin
@RequestMapping("/api/SYSTEM/sysModuleTree")
public class SystemAppModulesTreeBuilderAPI extends AbstractTreeBuilderController<SystemAppModuleTreeBuilder> {

	@RequestMapping({"/buildTree/{domainId}/"})
	@ResponseBody
	public List<TreeViewNodeBean> buildTree(@PathVariable long domainId,
			@ModelAttribute TreeParamModel treeParamModel, @RequestParam(defaultValue = "0") int expandLevel,
			@RequestParam(required = false) String selectedNodeId, @RequestParam(required = true) String requestId,
			HttpServletRequest request) throws Exception {

		request.setAttribute("domainId", domainId);
		
		return super.buildTree(treeParamModel, expandLevel, selectedNodeId, requestId, request);

	}
	
	@Override
	protected SystemAppModuleTreeBuilder getTreeBuilder(HttpServletRequest request) {
		return new SystemAppModuleTreeBuilder((long)request.getAttribute("domainId"));
	}

	@Override
	protected Object getInitParameter(HttpServletRequest request) {
		return null;
	}

}
